//
//  SwitfPch.swift
//  幸福互联
//
//  Created by apple on 2017/5/2.
//  Copyright © 2017年 youjindi. All rights reserved.
//

import UIKit
import Masonry
import JSONKit

let MainColor = UIColor(red:0/255.0, green: 87/255.0, blue: 165/255.0, alpha: 1.0)
let MainBackGroundColor = UIColor(red:241/255.0, green: 242/255.0, blue: 243/255.0, alpha: 1.0)

let ScreenHeight = UIScreen.main.bounds.size.height
let ScreenWidth = UIScreen.main.bounds.size.width


let PlaceHolderImage = UIImage(named: "image_empty")


func RandomColor() -> UIColor{
    let red = CGFloat(arc4random_uniform(255))/CGFloat(255.0)
    let green = CGFloat( arc4random_uniform(255))/CGFloat(255.0)
    let blue = CGFloat(arc4random_uniform(255))/CGFloat(255.0)
    let RandomColor = UIColor.init(red:red, green:green, blue:blue , alpha: 1)
    return RandomColor
}

func RGBColor(_ R: CGFloat,_ G: CGFloat,_ B: CGFloat) -> UIColor {
    let RGBColor = UIColor(red: R/255, green: G/255, blue: B/255, alpha: 1)
    return RGBColor
}

func getCurrVC() -> UIViewController{
    var currVC = UIViewController()
    var Rootvc = UIApplication.shared.keyWindow?.rootViewController
    if Rootvc != nil {
        if Rootvc is UINavigationController{
            let nav = Rootvc as! UINavigationController
            let v = nav.viewControllers.last
            currVC = v!
            Rootvc = v?.presentedViewController
        }else if Rootvc is UITabBarController{
            let tabVC = Rootvc as! UITabBarController
            currVC = tabVC
            Rootvc = tabVC.viewControllers?[tabVC.selectedIndex]
        }
    }

    return currVC
    
}

func getNavigation() -> NavigationController{
    return getCurrVC().navigationController as! NavigationController
}

func getUserInfo(_ string: String) -> String {
    return UserHandler.share.getUserInfo(string)
}

func pinyin(string: String) -> String {
    let str = NSMutableString(string: string) as CFMutableString
    if CFStringTransform(str, nil, kCFStringTransformMandarinLatin, false) == true {
        if CFStringTransform(str, nil, kCFStringTransformStripDiacritics, false) == true {
            return (str as String).uppercased()
        }
    }
    return str as String
}

//
//let attributedString = NSMutableAttributedString(string: self.integralLabel.text!)
//
//let color = UIColor.redColor()
//
//let normalAttributes = [NSForegroundColorAttributeName : color]
//
//attributedString.addAttributes(normalAttributes, range: NSMakeRange(0,2))
//
//self.integralLabel.attributedText = attributedString

open class XYView : UIView{
    open var saveID = String()
}

open class XYImageView : UIImageView{
    open var saveID = String()
}


